<?php
namespace app\index\controller;

use app\common\model\Apply as Applymodel;
use think\Controller;
use think\facade\Request;
use think\file;

class Index extends controller {

	public function index() {
		$this->redirect('index/apply');
		
	}
	public function apply() {
		// return $this->view->fetch('index');
		echo "系统暂无开放。";
	}

	public function savemsg() {
		$data = Request::param();
		$res = $this->validate($data, 'app\common\validate\Apply');
		if ($res !== true) {
			echo '<script>alert("' . $res . '");location.back()</script>';
		}
		// 个人照片
		$personalpic = Request::file('personalpic');
		$infop = $personalpic->rule('imgName_p')->move('uploads/personpic');
		// 执业医师照片1
		$doctorpica = Request::file('doctorpica');
		$infod = $doctorpica->rule('imgName_da')->move('uploads/doctorpica');
		// 执业医师照片2
		$doctorpicb = Request::file('doctorpicb');
		$infodb = $doctorpicb->rule('imgName_db')->move('uploads/doctorpicb');
		// 执业机构许可证，非必填
		$license = Request::file('license');
		if ($license) {
			$infol = $license->rule('imgName_l')->move('uploads/license');
			if ($infol) {
				$data['license'] = "license/" . $infol->getSavename();
			} else {
				$this->error($file->getError());
			}
		}

		if ($infop) {
			$data['personalpic'] = "personpic/" . $infop->getSavename();
		} else {
			$this->error($file->getError());
		}

		if ($infod) {
			$data['doctorpica'] = "doctorpica/" . $infod->getSavename();
		} else {
			$this->error($file->getError());
		}

		if ($infodb) {
			$data['doctorpicb'] = "doctorpicb/" . $infodb->getSavename();
		} else {
			$this->error($file->getError());
		}
		// 不让同一个手机号重复提交信息
		// $telphone = Request::param('telphone');
		// $result = Applymodel::where('telphone',$telphone)->find();
		// if($result){
		// 	$this->error('该手机号已经提交过申请，请勿重复提交，如有疑问请联系教育处');
		// }

		if (Applymodel::create($data)) {
			$this->success('提交成功,请耐心等待审核，注意短信通知！');
		} else {
			$this->error('数据保存失败，请重试！');
		}
	}
}
